//
//  ViewController.swift
//  uikit2
//
//  Created by 吴祥民 on 2024/1/2.
//

import UIKit

class ViewController: UIViewController,UISearchBarDelegate {
    
    let searchBar:UISearchBar = UISearchBar(frame: CGRectMake(20, 100, 280, 30))
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
                        //补帧动画
//        let imageView:UIImageView = UIImageView(frame: CGRectMake(100, 100, 100, 100))
//
//        //创建一个imageView
//        imageView.image = UIImage(named: "animate1.png")
//
//        imageView.backgroundColor = UIColor.gray
//        //设置imageView的高亮图片
////        imageView.highlightedImage = UIImage(named: "animate3.png")
//        //设置imageView为高亮状态
////        imageView.isHighlighted = true
//        self.view.addSubview(imageView)
//
//        //设置imageView动画效果
//        var array: [UIImage] = []
//        for i in 0..<3 {
//            let imageName = String(format: "animate%d.png", i+1)
//            if let image = UIImage(named: imageName) {
//                array.append(image)
//            }
//        }
//
//        // 设置imageView的动画数组
//        imageView.animationImages = array
//        // 设置动画的播放次数
//        imageView.animationRepeatCount = 0
//        // 设置播放一轮的时间
//        imageView.animationDuration = 1.5
//        // 开始动画
//        imageView.startAnimating()
        
                    //layer属性
//        let imageView = UIImageView(frame: CGRectMake(100, 100, 100, 100))
//        imageView.backgroundColor = UIColor.red
//        self.view.addSubview(imageView)
//        //设置圆角属性
////        imageView.layer.masksToBounds = true
////        imageView.layer.cornerRadius = 50
//        //设置边框
//        imageView.layer.borderWidth = 2
//        imageView.layer.borderColor = UIColor.green.cgColor
//
//        //设置阴影
//        imageView.layer.shadowColor = UIColor.purple.cgColor
//        imageView.layer.shadowOffset = CGSizeMake(10, 10)
//        imageView.layer.shadowOpacity = 1
                //uisearch
        searchBar.placeholder = "请输入关键字"
        //设置默认文字
//        searchBar.text = "剑圣"
        //设置搜索框风格
//        searchBar.barStyle = UIBarStyle.default
        //设置搜索框背景文字
//        searchBar.prompt = "背景"
        //渲染颜色
        searchBar.tintColor = UIColor.red
        //搜索框颜色
        searchBar.barTintColor = UIColor.white
        //设置搜索框附件视图
        searchBar.scopeButtonTitles = ["1","2","3","4"]
        //设置展示附件视图
        searchBar.showsScopeBar = true
        
        //设置代理
        searchBar.delegate = self
        
        self.view.addSubview(searchBar)
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        searchBar.resignFirstResponder()
    }
    
    //代理回掉函数
    //点击附件视图代理方法的回掉
    func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) {
        print(selectedScope)
    }
        
    //舒服框文字变化调用
    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
        print(searchText)
    }
    //点击视图触发方法
    func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
        print("点击了图书")
    }
    //点击搜索结果触发的方法
    func searchBarResultsListButtonClicked(_ searchBar: UISearchBar) {
        
    }
    
    //将要进入编辑状态触发的方法
    func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
        return true
    }
    //将要结束编辑触发
    func searchBarShouldEndEditing(_ searchBar: UISearchBar) -> Bool {
        return true
    }
    //检测用户输入文字
    func searchBar(_ searchBar: UISearchBar, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
        print(text)
        return true
    }
    
    //点击搜索
    func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
        
    }


}

